package com.dxy.lp.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Description TODO
 * @Author dangxianyue
 * @Date 2024/3/19 12:41
 */
public class MD5Utils {

    private static final String SALT = "suntek";// 加密盐

    public static String md5(String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");

            byte[] md5 = md.digest((data + SALT).getBytes(StandardCharsets.UTF_8));

            StringBuilder sb = new StringBuilder();
            for (byte b : md5) {
                //sb.append(Integer.toHexString(b & 0xff));
                // 字符串格式转成 16 进制
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void main(String[] args) {
        String content = null;
        System.out.println(md5(content));
    }

}
